<?php
require_once('merchant_fns.php');
check_merchant();
?>
    <form action="" method="get">
        查询订单:
        <input type="radio" name="method" value="0" <?php if (!isset($_GET['method']) || $_GET['method'] == 0) echo 'checked="true"'; ?>">订单号
        <input type="text" name="key">
        <input type="submit" value="查询">
    </form>
    <?php
    $mid = get_mid();
    $conn = db_connect();
    $array = array();
    $isset_key = isset($_GET['key']);
    if ($isset_key) {
        if ($_GET['method'] == 0) {
            $key = $_GET['key'];
            $sql = "call sp_query_order_id_by_mid_key({$mid},{$key})";
            $result = $conn->query($sql);
            while ($row = $result->fetch_array()) {
                array_push($array, $row['oid']);
            }
            $conn = db_connect();
        } else {
            array_push($array, $_GET['key']);
        }
    }
    ?>
    <hr>
<?php
$result = display_order();
while ($row = $result->fetch_array()) {
    if ($isset_key && !in_array($row['oid'], $array)) {
        continue;
    }
?>
    <p>订单号：<?php echo $row['oid']; ?></p>
    <p>订单时间：<?php echo $row['time']; ?></p>
    <p>订单状态：<select>
        <option value="待支付" <?php if($row['state']=='待支付')echo 'selected="true"'?>>待支付</option>
        <option value="配送中" <?php if($row['state']=='配送中')echo 'selected="true"'?>>配送中</option>
        <option value="已完成" <?php if($row['state']=='已完成')echo 'selected="true"'?>>已完成</option>
        <option value="已取消" <?php if($row['state']=='已取消')echo 'selected="true"'?>>已取消</option>
    </select></p>
    <p>订单总价：￥<?php echo $row['total']; ?></p>
    <p>买家姓名：<?php echo $row['sno']; ?></p>
    <p>买家联系方式：<?php echo $row['tel']; ?></p>
    <p>订单详情：</p>
    <table border="1" cellspacing="1">
                <tr>
                    <th width="200px" style="background:#66ccff;">名称</th>
                    <th width="100px" style="background:#66ccff;">单价</th>
                    <th width="100px" style="background:#66ccff;">数量</th>
                    <th width="200px" style="background:#66ccff;">商家名</th>
                </tr>
                <?php
                $detail = display_order_detail($row['oid']);
                while ($row2 = $detail->fetch_array()) {
                ?>
                    <tr>
                        <td><?php echo $row2['dname']; ?></td>
                        <td>￥<?php echo $row2['unit-price']; ?></td>
                        <td style="text-align: center;"><?php echo $row2['quantity']; ?></td>
                        <td><?php echo $row2['mname']; ?></td>
                    </tr>
                <?php    
                }
                ?>
                </table>
                <hr>
<?php
}
?>
<a href=merchant_center.php>返回上页</a>